package com.AAL.DAO;

import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IPriceDAO;
import com.AAL.Model.Price;
import com.AAL.Model.WheelDetail;
import com.AAL.Utils.HibernateUtil;

public class PriceDAO implements IPriceDAO {

	@Override
	public Price saveAndUpdatePrice(Price price) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(price);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return price;
	}

	@Override
	public Price deletePrice(int priceID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			Price price = (Price) session.load(Price.class, priceID);
			if (null != price) {
				session.delete(price);
			}
			session.getTransaction().commit();
			return price;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public Price getPrice(int priceID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Price price = (Price) session.load(Price.class, priceID);
		return price;
	}

	@Override
	public Price getNewPriceByWheeldetail(WheelDetail wheelDetail) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Price> getLstPriceByWheeldetail(WheelDetail wheelDetail) {
		// TODO Auto-generated method stub
		return null;
	}

}
